[id].vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. <template>
  2. <div>
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <HomePageNavigation1></HomePageNavigation1>
  6. <!-- 商圈详情 -->
  7. <div class="topicInfoBox">
  8. <div class="inner">
  9. <!-- 详情头部 -->
  10. <div class="infoHead">
  11. <div class="left">
  12. <div class="userInfo left">
  13. <el-badge value="楼主" class="item" type="warning">
  14. <img v-if='dataInfo.avatar' :src="dataInfo.avatar" alt="">
  15. <img v-else src='../../public/topic/Rectangle.png' alt="">
  16. </el-badge>
  17. <span>{{ dataInfo.nickname }}</span>
  18. </div>
  19. <div class="headContent left">
  20. <h2>{{ dataInfo.title }}</h2>
  21. <p v-show="dataInfo.group_name">
  22. 群聊:
  23. <span>{{ dataInfo.group_name }}</span>
  24. <button @click="joinGroup">加入群聊</button>
  25. </p>
  26. </div>
  27. </div>
  28. <div class="right">
  29. <div class="one" v-if="dataInfo.type == 1">科研</div>
  30. <div class="two" v-else-if="dataInfo.type == 2">维权</div>
  31. <div class="three" v-else-if="dataInfo.type == 3">讨论</div>
  32. <p>{{ dataInfo.updated_at }}</p>
  33. </div>
  34. </div>
  35. <!-- 详情页 文本+图片 -->
  36. <div class="infoContent" v-show="dataInfo.content">
  37. <div v-html="dataInfo.content"></div>
  38. </div>
  39. <div class="infoContent1" v-show="!dataInfo.content">
  40. <img src="../../public/topic/Document_empty.png" alt="">
  41. <span>可以看看大家的互动哦~</span>
  42. </div>
  43. <!-- 详情页评论 -->
  44. <div class="comment">
  45. <h3>评论</h3>
  46. <div class="commentList" v-for="item in replyList" v-show="page_total != 0">
  47. <div class="left">
  48. <img v-if='item.avatar' :src="item.avatar" alt="" >
  49. <img v-else src='../../public/topic/Rectangle.png' alt="">
  50. <span class="name">{{ item.nickname }} : </span>
  51. </div>
  52. <div class="center">
  53. <span class="context">{{ item.content }}</span>
  54. </div>
  55. <div class="right">
  56. <span class="time">{{ item.created_at }}</span>
  57. <!-- <span>回复</span> -->
  58. </div>
  59. </div>
  60. <div class="comment_empty" v-show="page_total == 0">
  61. <img src="../../public/topic/message_empty.png" alt="">
  62. <span>暂无评论</span>
  63. </div>
  64. </div>
  65. <!-- 分页 -->
  66. <div class="paginationBox" v-show="page_total != 0">
  67. <el-pagination background layout="prev, pager, next" :total="page_total" prev-text="上一页"
  68. next-text="下一页" :default-page-size="pageSize" @change="changePage" />
  69. </div>
  70. </div>
  71. </div>
  72. <div class="message">
  73. <div class="inner">
  74. <input v-model="content" placeholder="快来回复吧~" type="text" class="messageInput">
  75. <button class="btn" @click="addReply">确定</button>
  76. </div>
  77. </div>
  78. <!-- 页面底部 -->
  79. <HomeFoot1></HomeFoot1>
  80. </div>
  81. </template>
  82. <script setup>
  83. //1.引用模块 start ---------------------------------------->
  84. //使用ref和reactive动态变量
  85. import { ref, reactive, onMounted } from 'vue'
  86. import { useRoute } from 'vue-router';
  87. //使用官方ssr请求模块
  88. import { useNuxtApp, useFetch } from '#app'
  89. //使用element-plus组件
  90. import { ElPagination, ElBadge, ElInput, ElMessage, ElMessageBox } from 'element-plus';
  91. // axios请求
  92. const nuxtApp = useNuxtApp();
  93. const axios = nuxtApp.$axios;
  94. //1.引用模块 end ---------------------------------------->
  95. // 定义响应式数据
  96. const seoData = ref({
  97. title: '商圈',
  98. description: '默认描述',
  99. keywords: '默认关键词',
  100. image: 'https://example.com/default-image.jpg'
  101. });
  102. // 在 onMounted 钩子中获取数据
  103. onMounted(()=>{
  104. seoData.value.title = '商圈';
  105. seoData.value.description = '默认描述';
  106. seoData.value.keywords = '默认关键词';
  107. })
  108. //2.页面数据 start ---------------------------------------->
  109. const dataInfo = ref({})
  110. const groupId = useState("groupId", () => '')
  111. const replyList = useState("replyList", () => []) //评论列表
  112. //分页
  113. const page = ref(1)
  114. const pageSize = ref(5)
  115. let page_total = ref(0)
  116. const content = ref('')
  117. //2.页面数据 end ---------------------------------------->
  118. //3.获取商圈详情 start ---------------------------------------->
  119. const route = useRoute();
  120. const id = route.params.id; // 获取传递的 id 参数
  121. //页码发生改变
  122. const changePage = (val) => {
  123. console.log(val);
  124. page.value = val
  125. getTopicReply()
  126. }
  127. // 商圈信息
  128. const getTopicInfo = () => {
  129. let data = new FormData()
  130. data.append('id', id)
  131. axios.post('chat/getTopicInfo', data).then(res => {
  132. console.log('商圈信息', res);
  133. dataInfo.value = res.data
  134. groupId.value = res.data.group_id
  135. console.log(groupId.value);
  136. })
  137. }
  138. // 回复商圈 列表
  139. const getTopicReply = () => {
  140. let data = new FormData()
  141. data.append('id', id)
  142. data.append('page', page.value)
  143. data.append('page_size', pageSize.value)
  144. axios.post('chat/getTopicReply', data).then(res => {
  145. console.log('回复商圈列表 ', res);
  146. replyList.value = res.data.data
  147. // page_total.value = res.data.total
  148. page_total.value = res.data.total
  149. console.log("replyList", replyList);
  150. })
  151. }
  152. onMounted(() => {
  153. getTopicInfo(); //商圈信息
  154. getTopicReply(); //回复商圈列表
  155. })
  156. //加入群聊
  157. const joinGroup = () => {
  158. ElMessageBox.confirm(
  159. '加入群聊后,页面跳转至后台群聊页面',
  160. '是否加入群聊?',
  161. {
  162. confirmButtonText: '是',
  163. cancelButtonText: '否',
  164. center: true,
  165. }
  166. ).then(() => {
  167. console.log('groupId.value', groupId.value);
  168. let data = new FormData()
  169. data.append('group_id', groupId.value)
  170. axios.post('chat/joinGroup', data).then(res => {
  171. console.log('加入群聊 ', res);
  172. if (res.code == 0 && res.message !== '已加入群') {
  173. ElMessage.error(res.message)
  174. } else if (res.code == 0 && res.message == '已加入群') {
  175. ElMessage({
  176. message: res.message,
  177. type: 'success',
  178. })
  179. setTimeout(() => {
  180. window.open('http://admindev.bjzxtw.org.cn/#/hall', '_blank');
  181. }, 1000)
  182. } else if (res.code == 200) {
  183. ElMessage({
  184. message: '加入成功',
  185. type: 'success',
  186. })
  187. setTimeout(() => {
  188. window.open('http://admindev.bjzxtw.org.cn/#/hall', '_blank');
  189. }, 1000)
  190. }
  191. })
  192. }).catch(() => {
  193. ElMessage({
  194. type: 'error',
  195. message: '已取消',
  196. })
  197. })
  198. }
  199. // 回复商圈
  200. const addReply = () => {
  201. let data = new FormData()
  202. data.append('id', id)
  203. data.append('content', content.value)
  204. axios.post('chat/addReply', data).then(res => {
  205. console.log('回复商圈 ', res);
  206. if (res.code == 0) {
  207. ElMessage.error(res.message)
  208. getTopicReply();
  209. } else if (res.code == 200) {
  210. ElMessage({
  211. message: '回复成功',
  212. type: 'success',
  213. })
  214. content.value = ''
  215. getTopicReply();
  216. }
  217. })
  218. }
  219. //3.获取商圈详情 end ---------------------------------------->
  220. </script>
  221. <style lang="less" scoped>
  222. .topicInfoBox {
  223. .inner {
  224. width: 1200px;
  225. margin: 0 auto;
  226. //信息头部
  227. .infoHead {
  228. height: 200px;
  229. padding: 65px 0 60px 40px;
  230. border-bottom: 1px solid rgba(0, 0, 0, 0.10);
  231. box-sizing: border-box;
  232. >.left {
  233. .userInfo {
  234. margin-right: 90px;
  235. .item {
  236. margin-top: -5px;
  237. margin-right: -5px;
  238. :deep(.el-badge__content.is-fixed) {
  239. position: absolute;
  240. right: calc(1px + var(--el-badge-size) / 2);
  241. top: 0;
  242. transform: translateY(-31%) translateX(79%);
  243. z-index: var(--el-index-normal);
  244. }
  245. img {
  246. width: 66px;
  247. height: 66px;
  248. vertical-align: middle;
  249. border-radius: 50%;
  250. }
  251. }
  252. span {
  253. margin-left: 15px;
  254. font-family: Microsoft YaHei, Microsoft YaHei;
  255. font-weight: 400;
  256. font-size: 18px;
  257. color: #333333;
  258. }
  259. }
  260. .headContent {
  261. h2 {
  262. width: 750px;
  263. height: 56px;
  264. line-height: 28px;
  265. display: -webkit-box;
  266. -webkit-box-orient: vertical;
  267. -webkit-line-clamp: 2;
  268. overflow: hidden;
  269. text-overflow: ellipsis;
  270. word-break: break-all;
  271. font-family: Microsoft YaHei, Microsoft YaHei;
  272. font-weight: bold;
  273. font-size: 20px;
  274. color: #333333;
  275. margin-bottom: 26px;
  276. }
  277. >p {
  278. font-family: Microsoft YaHei, Microsoft YaHei;
  279. font-weight: 400;
  280. font-size: 16px;
  281. color: #333333;
  282. button {
  283. width: 86px;
  284. height: 32px;
  285. background-color: #028e21;
  286. color: #fff;
  287. border: none;
  288. margin-left: 100px;
  289. }
  290. }
  291. }
  292. }
  293. >.right {
  294. position: relative;
  295. div {
  296. position: absolute;
  297. right: 0;
  298. top: 0;
  299. width: 71px;
  300. height: 32px;
  301. line-height: 32px;
  302. text-align: center;
  303. background-color: #d9f0d6;
  304. margin-bottom: 29px;
  305. font-family: Microsoft YaHei, Microsoft YaHei;
  306. font-weight: 400;
  307. font-size: 16px;
  308. color: #33B023;
  309. }
  310. .one {
  311. color: #FFAA33;
  312. background-color: #fbebd5;
  313. }
  314. .two {
  315. color: #33B023;
  316. background-color: #d5ecd2;
  317. }
  318. .three {
  319. color: #666;
  320. background-color: #ebebeb;
  321. }
  322. p {
  323. width: 150px;
  324. text-align: right;
  325. position: absolute;
  326. top: 62px;
  327. right: 0;
  328. }
  329. }
  330. }
  331. // 有详情信息
  332. .infoContent {
  333. width:1196px;
  334. overflow: hidden;
  335. padding: 40px 46px;
  336. font-family: Microsoft YaHei, Microsoft YaHei;
  337. font-size: 20px;
  338. line-height: 40px;
  339. box-sizing: border-box;
  340. div{
  341. word-wrap: break-word; /* 强制长单词或 URL 换行 */
  342. overflow-wrap: break-word; /* 现代推荐用法,等同于 word-wrap */
  343. white-space: pre-wrap; /* 保留空白字符并允许自动换行 */
  344. word-break: break-all; /* 强制在任意字符处换行 */
  345. }
  346. }
  347. .leftBottom::v-deep p{
  348. width:1200px;
  349. white-space: pre-wrap;
  350. }
  351. //没有详情信息
  352. .comment_empty,
  353. .infoContent1 {
  354. height: 300px;
  355. line-height: 260px;
  356. text-align: center;
  357. img {
  358. width: 78px;
  359. height: 78px;
  360. vertical-align: -25px;
  361. vertical-align: middle;
  362. margin-right: 20px;
  363. }
  364. span {
  365. font-family: Microsoft YaHei, Microsoft YaHei;
  366. font-weight: bold;
  367. font-size: 26px;
  368. color: #CCCCCC;
  369. }
  370. }
  371. //评论
  372. .comment {
  373. h3 {
  374. height: 100px;
  375. padding-top: 30px;
  376. box-sizing: border-box;
  377. border-bottom: 1px solid #E1E1E1;
  378. font-family: Microsoft YaHei, Microsoft YaHei;
  379. font-weight: 400;
  380. font-size: 22px;
  381. color: #000000;
  382. }
  383. .commentList {
  384. // height: 112px;
  385. border: 1px solid #E1E1E1;
  386. background-color: #fafafa;
  387. margin-top: 20px;
  388. padding: 30px 30px;
  389. box-sizing: border-box;
  390. display: flex;
  391. align-items: flex-start;
  392. justify-content: space-between;
  393. .left {
  394. width:400px;
  395. margin-right: 40px;
  396. // overflow: hidden;
  397. display: flex;
  398. justify-content: space-between;
  399. img {
  400. // float: left;
  401. width: 52px;
  402. height: 52px;
  403. border-radius: 50%;
  404. vertical-align: middle;
  405. margin-right: 15px;
  406. }
  407. span{
  408. // float: left;
  409. height: 52px;
  410. line-height: 22px;
  411. padding-top: 10px;
  412. }
  413. .name {
  414. width: 100px;
  415. font-family: Microsoft YaHei, Microsoft YaHei;
  416. font-weight: 400;
  417. font-size: 16px;
  418. color: #333333;
  419. margin-right: 30px;
  420. width: 100px;
  421. white-space: nowrap;
  422. overflow: hidden;
  423. text-overflow: ellipsis;
  424. display: block;
  425. }
  426. }
  427. .center {
  428. .context {
  429. width: 700px;
  430. margin-right: 40px;
  431. display: -webkit-box;
  432. -webkit-box-orient: vertical;
  433. -webkit-line-clamp: 2;
  434. overflow: hidden;
  435. text-overflow: ellipsis;
  436. word-break: break-all;
  437. font-family: Microsoft YaHei, Microsoft YaHei;
  438. font-weight: bold;
  439. font-size: 16px;
  440. color: #333333;
  441. }
  442. }
  443. .right {
  444. .time {
  445. display: block;
  446. width: 200px;
  447. font-family: Microsoft YaHei, Microsoft YaHei;
  448. font-weight: 400;
  449. font-size: 16px;
  450. color: #999999;
  451. margin-right: 30px;
  452. }
  453. span {
  454. font-family: Microsoft YaHei, Microsoft YaHei;
  455. font-weight: 400;
  456. font-size: 16px;
  457. color: #333333;
  458. }
  459. }
  460. }
  461. // .comment_empty {
  462. // height: 200px;
  463. // line-height: 200px;
  464. // text-align: center;
  465. // img {
  466. // width: 78px;
  467. // height: 78px;
  468. // vertical-align: -25px;
  469. // margin-right: 20px;
  470. // }
  471. // span {
  472. // font-family: Microsoft YaHei, Microsoft YaHei;
  473. // font-weight: bold;
  474. // font-size: 26px;
  475. // color: #CCCCCC;
  476. // }
  477. // }
  478. }
  479. }
  480. }
  481. //评论回复
  482. .message {
  483. width: 1200px;
  484. margin: 0 auto;
  485. padding: 0px 25px;
  486. box-sizing: border-box;
  487. height: 145px;
  488. line-height: 145px;
  489. background-color: #ecf5ee;
  490. .inner {
  491. .messageInput {
  492. width: 1000px;
  493. height: 67px;
  494. outline: none;
  495. border: 1px solid #E1E1E1;
  496. background-color: #fafafa;
  497. font-family: Microsoft YaHei, Microsoft YaHei;
  498. font-weight: 400;
  499. font-size: 18px;
  500. color: #666;
  501. padding: 0 20px;
  502. box-sizing: border-box;
  503. }
  504. .btn {
  505. width: 115px;
  506. height: 40px;
  507. border: none;
  508. background-color: #028e21;
  509. color: #fff;
  510. border-radius: 6px;
  511. margin-left: 36px;
  512. font-family: Microsoft YaHei, Microsoft YaHei;
  513. font-weight: 400;
  514. font-size: 16px;
  515. }
  516. }
  517. }
  518. //分页
  519. .paginationBox {
  520. display: flex;
  521. justify-content: center;
  522. margin-top: 60px;
  523. margin-bottom: 90px;
  524. // 鼠标移入后字体颜色
  525. :deep(.el-pagination:hover) {
  526. color: #139609;
  527. }
  528. :deep(.el-pagination.is-background .btn-next),
  529. :deep(.el-pagination.is-background .btn-prev) {
  530. width: 70px;
  531. height: 34px;
  532. margin: 0px 10px;
  533. border-radius: 4px;
  534. }
  535. :deep(.el-pagination.is-background .el-pager li) {
  536. margin: 0px 10px;
  537. width: 38px;
  538. height: 34px;
  539. border-radius: 4px;
  540. }
  541. :deep(.el-pagination.is-background .btn-next.is-active),
  542. :deep(.el-pagination.is-background .btn-prev.is-active),
  543. :deep(.el-pagination.is-background .el-pager li.is-active) {
  544. background-color: #028e21;
  545. color: #fff;
  546. }
  547. }
  548. </style>